import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BookingQueueManagementApi } from '#/api/spa/booking/queuemanagement';

import { DICT_SPA_TYPE } from '#/utils/dictSpa';
import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'bookingOrderId',
      label: '预约订单ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入预约订单ID',
      },
    },
    {
      fieldName: 'queueCode',
      label: '排队编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队编码',
      },
    },
    {
      fieldName: 'queueNumber',
      label: '排队号码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队号码',
      },
    },
    {
      fieldName: 'queueType',
      label: '排队类型',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择排队类型',
      },
    },
    {
      fieldName: 'queueCategory',
      label: '排队分类',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队分类',
      },
    },
    {
      fieldName: 'queuePriority',
      label: '排队优先级',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队优先级',
      },
    },
    {
      fieldName: 'queueStartTime',
      label: '开始排队时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'estimatedWaitTime',
      label: '预估等待时间(分钟)',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'actualWaitTime',
      label: '实际等待时间(分钟)',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'queueEndTime',
      label: '结束排队时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'queuePosition',
      label: '排队位置',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队位置',
      },
    },
    {
      fieldName: 'queueLength',
      label: '当前队列长度',
      component: 'Input',
      componentProps: {
        placeholder: '请输入当前队列长度',
      },
    },
    {
      fieldName: 'queueArea',
      label: '排队区域',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队区域',
      },
    },
    {
      fieldName: 'queueStation',
      label: '排队站点',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排队站点',
      },
    },
    {
      fieldName: 'queueStatus',
      label: '排队状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'callTime',
      label: '叫号时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'callCount',
      label: '叫号次数',
      component: 'Input',
      componentProps: {
        placeholder: '请输入叫号次数',
      },
    },
    {
      fieldName: 'lastCallTime',
      label: '最后叫号时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'resourceReadyTime',
      label: '资源准备完成时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'resourceReadyStatus',
      label: '资源准备状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'notificationSent',
      label: '是否已发送通知',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'notificationMethod',
      label: '通知方式',
      component: 'Input',
      componentProps: {
        placeholder: '请输入通知方式',
      },
    },
    {
      fieldName: 'notificationTime',
      label: '通知时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'orgId',
      label: '组织ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入组织ID',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'bookingOrderId',
      label: '预约订单ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入预约订单ID',
      },
    },
    {
      fieldName: 'queueCode',
      label: '排队编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队编码',
      },
    },
    {
      fieldName: 'queueNumber',
      label: '排队号码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队号码',
      },
    },
    {
      fieldName: 'queueType',
      label: '排队类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择排队类型',
      },
    },
    {
      fieldName: 'queueCategory',
      label: '排队分类',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队分类',
      },
    },
    {
      fieldName: 'queuePriority',
      label: '排队优先级',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队优先级',
      },
    },
    {
      fieldName: 'queueStartTime',
      label: '开始排队时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'estimatedWaitTime',
      label: '预估等待时间(分钟)',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'actualWaitTime',
      label: '实际等待时间(分钟)',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'queueEndTime',
      label: '结束排队时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'queuePosition',
      label: '排队位置',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队位置',
      },
    },
    {
      fieldName: 'queueLength',
      label: '当前队列长度',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入当前队列长度',
      },
    },
    {
      fieldName: 'queueArea',
      label: '排队区域',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队区域',
      },
    },
    {
      fieldName: 'queueStation',
      label: '排队站点',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排队站点',
      },
    },
    {
      fieldName: 'queueStatus',
      label: '排队状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择排队状态',
      },
    },
    {
      fieldName: 'callTime',
      label: '叫号时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'callCount',
      label: '叫号次数',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入叫号次数',
      },
    },
    {
      fieldName: 'lastCallTime',
      label: '最后叫号时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'resourceReadyTime',
      label: '资源准备完成时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'resourceReadyStatus',
      label: '资源准备状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择资源准备状态',
      },
    },
    {
      fieldName: 'notificationSent',
      label: '是否已发送通知',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        placeholder: '请选择是否已发送通知',
      },
    },
    {
      fieldName: 'notificationMethod',
      label: '通知方式',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入通知方式',
      },
    },
    {
      fieldName: 'notificationTime',
      label: '通知时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'orgId',
      label: '组织ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入组织ID',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BookingQueueManagementApi.BookingQueueManagement>['columns'] {
  return [
    {
      field: 'id',
      title: '排队ID',
      minWidth: 120,
    },
    {
      field: 'bookingOrderId',
      title: '预约订单ID',
      minWidth: 120,
    },
    {
      field: 'queueCode',
      title: '排队编码',
      minWidth: 120,
    },
    {
      field: 'queueNumber',
      title: '排队号码',
      minWidth: 120,
    },
    {
      field: 'queueType',
      title: '排队类型',
      minWidth: 120,
    },
    {
      field: 'queueCategory',
      title: '排队分类',
      minWidth: 120,
    },
    {
      field: 'queuePriority',
      title: '排队优先级',
      minWidth: 120,
    },
    {
      field: 'queueStartTime',
      title: '开始排队时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'estimatedWaitTime',
      title: '预估等待时间(分钟)',
      minWidth: 120,
    },
    {
      field: 'actualWaitTime',
      title: '实际等待时间(分钟)',
      minWidth: 120,
    },
    {
      field: 'queueEndTime',
      title: '结束排队时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'queuePosition',
      title: '排队位置',
      minWidth: 120,
    },
    {
      field: 'queueLength',
      title: '当前队列长度',
      minWidth: 120,
    },
    {
      field: 'queueArea',
      title: '排队区域',
      minWidth: 120,
    },
    {
      field: 'queueStation',
      title: '排队站点',
      minWidth: 120,
    },
    {
      field: 'queueStatus',
      title: '排队状态',
      minWidth: 120,
    },
    {
      field: 'callTime',
      title: '叫号时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'callCount',
      title: '叫号次数',
      minWidth: 120,
    },
    {
      field: 'lastCallTime',
      title: '最后叫号时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'resourceReadyTime',
      title: '资源准备完成时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'resourceReadyStatus',
      title: '资源准备状态',
      minWidth: 120,
    },
    {
      field: 'notificationSent',
      title: '是否已发送通知',
      minWidth: 120,
    },
    {
      field: 'notificationMethod',
      title: '通知方式',
      minWidth: 120,
    },
    {
      field: 'notificationTime',
      title: '通知时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'storeId',
      title: '门店ID',
      minWidth: 120,
    },
    {
      field: 'orgId',
      title: '组织ID',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
